#!/bin/bash

# create executable JAR
../gradlew build

MODULE_NAME=${PWD##*/}

echo $PROFILES
[ -z "$IMAGE_NAME" ] && IMAGE_NAME=oasis/$MODULE_NAME
[ -z "$IMAGE_TAG" ] && IMAGE_TAG=1.0
[ -z "$SERVER_PORT" ] && SERVER_PORT=1106
[ -z "$TAG_ARGS" ] && TAG_ARGS=$IMAGE_NAME/$IMAGE_TAG
[ -z "$CONFIG_HOST" ] && CONFIG_HOST=10.10.40.55
[ -z "$CONFIG_PORT" ] && CONFIG_PORT=8848
[ -z "$DISCOVERY_HOST" ] && DISCOVERY_HOST=10.10.40.55
[ -z "$DISCOVERY_PORT" ] && DISCOVERY_PORT=8848
[ -z "$CONFIG_NAMESPACE" ]
[ -z "$DOCKERIZE_TIMEOUT" ] && DOCKERIZE_TIMEOUT=60s
[ -z "$JAVA_OPTS" ] && JAVA_OPTS=-Xmx512m
[ -z "$PROFILES" ] && PROFILES=test
echo $PROFILES
JAR_FILE=$MODULE_NAME".jar"
echo $JAR_FILE

docker build --build-arg JAR_FILE="$JAR_FILE" \
    --build-arg SOURCE_JAR=build/libs/*.jar \
    --build-arg PORT=$SERVER_PORT \
    --build-arg AUTH_HOST=$AUTH_HOST \
    --build-arg AUTH_PORT=$AUTH_PORT \
    --build-arg CONFIG_HOST=$CONFIG_HOST \
    --build-arg CONFIG_PORT=$CONFIG_PORT \
    --build-arg DISCOVERY_HOST=$DISCOVERY_HOST \
    --build-arg DISCOVERY_PORT=$DISCOVERY_PORT \
    --build-arg CONFIG_NAMESPACE=$CONFIG_NAMESPACE \
    --build-arg DOCKERIZE_TIMEOUT=$DOCKERIZE_TIMEOUT \
    --build-arg JAVA_OPTS=$JAVA_OPTS \
    -t "$TAG_ARGS" .